package com.flong.juc.charter1;

/**
 * @Author:liangjl
 * @Date: 2020/7/4-21:23
 * @Eamil:jilongliang@sina.com
 * @Description:
 */
public class MyTest9 {
    public static void main(String[] args) throws InterruptedException {
        MyTest9Thread test9Thread = new MyTest9Thread();
        Thread t = new Thread(() -> {
            test9Thread.run();
        });


        //修改线程名称为A
        t.setName("A");
        t.start();
        Thread.sleep(10);

        Thread t2 = new Thread(() -> {
            test9Thread.run();
        });

        t2.start();
        Thread.sleep(10);

    }
}

class MyTest9Thread {
    //不会释放同步锁
    public void run() {
        System.out.println("线程开始");
        //判断当前线程名称是否为A的线程
        if ("A".equals(Thread.currentThread().getName())) {
            System.out.println("A线程一直挂起");
            Thread.currentThread().suspend();
        }
        System.out.println("线程结束");

    }
}
